package yh.thread.threadcreate;

import java.util.concurrent.ThreadFactory;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 自定义线程
 * @author: zyh
 * @date: 2024/10/31 18:44
 **/
public class MyCustomThread implements ThreadFactory {


    private  String threadPrefix;

    private final AtomicInteger atomicInteger = new AtomicInteger(1);


    public MyCustomThread(String threadPrefix) {
        this.threadPrefix = threadPrefix + "-" + atomicInteger.getAndIncrement();
    }

    @Override
    public Thread newThread(Runnable r) {
        Thread thread = new Thread(r);
        thread.setName(threadPrefix);
        return thread;
    }
}
